package main.lph;

import java.util.Map;
import massageBox.Utility;
import massageBox.Utility.Room;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.ToggleButton;
import massageBox.Sender;


public class LightActivity extends Activity {
	
	Map<String, Object> changeMap = null;
	Sender sender = new Sender();
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		Log.i("info","LightActivity.onCreate was lunch");
		
		super.onCreate(savedInstanceState);
	    
	    setContentView(R.layout.light_layout);
	    	
	    // TODO Auto-generated method stub
	}
	
	//itoggleButton for sleeping room - switch light on | light off
		public void itoggleButtonSleeping(View v){
			
			Log.i("info","LightActivity.itoggleButtonSleeping was lunch");
			Room room = Utility.Room.SLEEPING;
		
			ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButtonSleeping);
			if (tb.isChecked()){
				//send message for switch on light for sleeping room
				changeMap = sender.sendLight("SLEEPING", true);
				sendResult("SLEEPING","on");	
			}
			else{
				//send message for switch off light for sleeping room
				changeMap = sender.sendLight("SLEEPING", false);
				sendResult("SLEEPING","off");
			}
		}
		
		
		//itoggleButton for living room - switch light on | light off
		public void itoggleButtonLiving(View v){
		
			ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButtonLiving);
			if (tb.isChecked()){
				//send message for switch on light
				changeMap = sender.sendLight("LIVING", true);
				sendResult("LIVING","on");
			}
			else{
				//send message for switch off light
				changeMap = sender.sendLight("LIVING", false);
				sendResult("LIVING","off");
			}
		}
		
		//itoggleButton for dining room - switch light on | light off
		public void itoggleButtonDiner(View v){
		
			ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButtonDining);
			if (tb.isChecked()){
				//sender.sendOld();
				//send message for switch on light
				changeMap = sender.sendLight("DINING", true);
				sendResult("DINING","on");
			}
			else{
				//send message for switch off light
				changeMap = sender.sendLight("DINING", false);
				sendResult("DINING","off");
			}
		}
		
		//itoggleButton for kitchen room - switch light on | light off
		public void itoggleButtonKitchen(View v){
		
			
			
			ToggleButton tb = (ToggleButton) findViewById(R.id.toggleButtonKitchen);
			if (tb.isChecked()){
				//send message for switch on light
				changeMap = sender.sendLight("KITCHEN", true);
				sendResult("KITCHEN","on");
			}
			else{
				//send message for switch off light
				changeMap = sender.sendLight("KITCHEN", false);
				sendResult("KITCHEN","off");
			}
		}
		
		
		//sed the current result and display msg in textfield of app
		private void sendResult(String room, String status){
			
			String returnString = sender.send(changeMap, "LP.LIGHTCONTROL");
			
			TextView textView1 = (TextView) findViewById(R.id.textView_light);
			
			textView1.setText("Msg: "+room+ " - switch: "+status+" Send: "+returnString);
		}
		


}
